package compiler.node;

import compiler.SymbolTable;
import compiler.type.Type;
import org.antlr.runtime.Token;
import org.antlr.runtime.tree.CommonTree;

import java.util.Stack;
/*

    This file is part of Logica-Logike.

    Logica-Logike is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation version 3 of the License.

    Logica-Logike is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Logica-Logike.  If not, see <http://www.gnu.org/licenses/>.

 */
public class Node extends CommonTree {
	private Type type;
	
    public Node(Token token) {
        super(token);
    }

    public Node getChild(int i) {
        return (Node) super.getChild(i);
    }

    public void toString(StringBuilder builder, String indent) {
        builder.append(indent);
        builder.append(getClass().getSimpleName());
        builder.append("<").append(getText()).append(">");
        builder.append('\n');

        int count = getChildCount();
        for (int i = 0; i < count; i++) {
            getChild(i).toString(builder, indent + "   ");
        }
    }

    public String toString() {
        StringBuilder builder = new StringBuilder();
        toString(builder, "");

        return builder.toString();
    }

    protected void execute(Stack stack) {
    	int count = getChildCount();
    	for(int i=0; i<count;i++){
    		getChild(i).execute(stack);
    	}
	}
    
    protected void analyze(SymbolTable st){
        int count = getChildCount();
    	for(int i=0;i<count;i++){
    		getChild(i).analyze(st);
    	}
    }
}
